package com.longge;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @创建人 xinglongge
 * @创建时间 2021/11/19
 * @描述
 */
public class IsIsomorphic {
    public boolean isIsomorphic(String s, String t) {

        HashMap<Character, Character> map = new HashMap<>();
        char[] sChars = s.toCharArray();
        char[] tChars = t.toCharArray();
        int i = 0;
        while (i < sChars.length) {
            if (map.containsKey(sChars[i]) && !map.get(sChars[i]).equals(tChars[i])) {
                return false;
            }
            map.put(sChars[i], tChars[i]);
            i++;
        }
        return new HashSet<>(map.values()).size() == map.size();
    }
}
